package com.lingnan.controller;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.lingnan.service.WeChatService;
import com.lingnan.util.Result;
import com.lingnan.util.ResultGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author 梁兴达
 * @Date 2022/4/16 20:13:17
 * @Version 1.0
 */
@RestController
@RequestMapping("/weChat")
public class WeChatController {


    @Autowired
    private WeChatService weChatService;

    @GetMapping("/getOpenId")
    public Result getCode(@RequestParam(value = "code")String  code){
//        System.out.println(code);
        if (!ObjectUtils.isEmpty(code)){
            JSONObject codetoopenid = weChatService.codetoopenid(code);
            System.out.println(codetoopenid);
            if (!ObjectUtils.isEmpty(codetoopenid)){
                return ResultGenerator.genSuccessResult(200,codetoopenid,"获取成功");
            }
            return ResultGenerator.genErrorResult(201,"获取失败");
        }
        return ResultGenerator.genErrorResult(201,"输入不能为空");
    }

}
